// 将频道数据提取到自定义hook中
import { fetchChannelAPI } from "@/apis/list.ts"
import { useEffect, useState } from "react"
import type { ChannelItem } from "@/apis/list.ts"

function useTabs() {
	const [channels, setChannels] = useState<ChannelItem[]>([])

	useEffect(() => {
		const getChannels = async () => {
			try {
				const res = await fetchChannelAPI()
				setChannels(res.data.data.channels)
			} catch (error) {
				console.log(error)
				throw new Error("fetch channel error")
			}
		}
		getChannels()
	}, [])

	return {
		channels,
	}
}

export { useTabs }
